/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package summerprojectFX.view;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.util.ArrayList;

import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.EventHandler;
import javafx.event.EventType;
import javafx.geometry.Insets;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.control.ScrollPane;
import javafx.scene.effect.InnerShadow;
import javafx.scene.effect.InnerShadowBuilder;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.scene.text.TextBuilder;
import javafx.stage.Stage;
import summerprojectFX.controller.HelpItem;
import summerprojectFX.model.Song;

/**
 *
 * @author Milan
 */
public class HelpContent {
    private ListView<String> content;
    
    public void start(Stage primaryStage)  {
        primaryStage.setTitle("Help");
                
		// Gets Monitors resolution for the JFrame
		Toolkit toolkit = Toolkit.getDefaultToolkit();
		final Dimension scrnsize = toolkit.getScreenSize();
                
                Group root = new Group();
		Scene scene = new Scene(root, scrnsize.width / 2,
				scrnsize.height / 2, Color.LIGHTGRAY);
                
                GridPane gridpane = new GridPane();
		gridpane.setPadding(new Insets(5));
		gridpane.setHgap(10);
		gridpane.setVgap(10);
                final ScrollPane sp = new ScrollPane();
                
                sp.setPrefHeight(scrnsize.getHeight() / 2.4);
		sp.setPrefWidth(scrnsize.getWidth() / 3);
                
                Image image = new Image("lib/keychart.png");
                ImageView iv = new ImageView(image);
                iv.setFitHeight(800);
                iv.setFitWidth(650);
                
                Image image2 = new Image("lib/fried.jpg");
                ImageView iv2 = new ImageView(image2);
                iv2.setFitWidth(800);
                
                final HelpItem key = new HelpItem("Finding Key", iv);
                final HelpItem format = new HelpItem("Formating Documents", iv2);
                
               ObservableList<String> hContentList =FXCollections.observableArrayList(key.getName(), format.getName());
                
                content = new ListView<String>(hContentList);
		content.setPrefWidth(150);
		content.setPrefHeight(scrnsize.getHeight() / 2.4);
                
                InnerShadow iShadow = InnerShadowBuilder.create().offsetX(1.5f)
				.offsetY(1.5f).build();
                
                Text contentLbl = TextBuilder.create()
				.effect(iShadow)
				.fill(Color.DARKGREY).font(Font.font(null, FontWeight.BOLD, 15)).build();
                contentLbl.setText("Contents");
                Label test = new Label();
                
                sp.setContent(key.getImage());
                content.selectionModelProperty().getValue().selectFirst();
                VBox contentListBox = new VBox();
                HBox contentSet = new HBox();
                contentSet.getChildren().addAll(content, sp);
                contentSet.setSpacing(20);
                contentListBox.getChildren().addAll(contentLbl, contentSet);
                gridpane.add(contentListBox, 1, 2);
                
                content.setStyle("-fx-background-color: gray;");
                sp.setStyle("-fx-background-color: white;");
                root.getChildren().add(gridpane);
                content.setOnMouseClicked(new EventHandler<MouseEvent>() {

			@Override
			public void handle(MouseEvent event) {
				String title = content.getSelectionModel()
						.getSelectedItem();
                                if(title.equals(key.getName())){
                                    sp.setContent(key.getImage());
                                }else if(title.equals(format.getName())){
                                    sp.setContent(format.getImage());
                                }
			}
		});
                scene.widthProperty().addListener(new ChangeListener<Number>() {
        			@Override
        			public void changed(
        					ObservableValue<? extends Number> observableValue,
        					Number oldSceneWidth, Number newSceneWidth) {
                                                sp.setPrefWidth(newSceneWidth.doubleValue() / 2);

        			}
        		});

        		scene.heightProperty().addListener(new ChangeListener<Number>() {
        			@Override
        			public void changed(
        					ObservableValue<? extends Number> observableValue,
        					Number oldSceneHeight, Number newSceneHeight) {
        				content.setPrefHeight(newSceneHeight.doubleValue() / 1.2);

        			}
        		});
                
                primaryStage.setScene(scene);
		primaryStage.show();
    }
}
